<?php
	$seitcm_class_id = isset($seitcm_class_id) ? $seitcm_class_id : 0;
	$seitcm_mark_list = seitcm_get_class_student_list($seitcm_class_id);
	?>
	<div id="seitcm_wrapper_ms">
		<div id="seitcm_header">
			<div id="seitcm_head_logo">
				<h1><?php _e('Sunshine Education','SEITCM') ?></h1>
				<h2><?php _e('Score list','SEITCM') ?></h2>
			</div>
			<div id="seitcm_head_menu">
				<?php if(current_user_can('seitcm_scores_update')) {?>
        		<a class="seitcm_button" href="admin.php?page=seitcm_class_option_menu&module=score&class=<?php echo $seitcm_class_id?>&action=examinationscores">Add exam scores</a>
				<?php }?>
				<a class="seitcm_button" href="admin.php?page=seitcm_class_option_menu&module=studentlist&class=<?php echo $seitcm_class_id?>">Student list</a>
				<a class="seitcm_button" href="admin.php?page=seitcm_class_option_menu&module=list">Class list</a>
			</div>
			<div class="seitcm_clearfload">
			</div>
		</div>
		<div class="seitcm_bigwidget_block">
			<div class="seitcm_bigwidget_block_inner">
				<table class="seitcm_grid"><tbody>
					<tr>
						<th><?php _e('NO','SEITCM')?></th>
						<th><?php _e('Real Name','SEITCM')?></th>
						<th><?php _e('Date of birth','SEITCM')?></th>
						<th><?php _e('Periodic Reviews','SEITCM')?></th>
						<th><?php _e('Examination Scores','SEITCM')?></th>
						
						<?php if(current_user_can('seitcm_scores_update')) {?>
						<th>Control</th>
						<?php }?>
					</tr>
					<?php
						$i=0;
						foreach ($seitcm_mark_list as $seitcm_row)
						{
							?>
							<tr>
								<td><?php echo ++$i?></td>
								<td><?php echo get_user_meta($seitcm_row->ID, 'first_name', true) . ' ' . get_user_meta($seitcm_row->ID, 'last_name', true)?></td>
								<td><?php echo get_user_meta($seitcm_row->ID, 'dob', true)?></td>	
								<td>
									<?php 
									//Periodic Reviews
									$total = 0;
									$detail = '<div style="height:250px; overflow-y:scroll; border: 1px #cfcfcf solid;border-radius: 5px 5px 0px 0px;margin-top: 5px;"><table class="seitcm_grid">
													<tr>
														<th>'.__('Score','SEITCM').'</th>
														<th>'.__('Skill','SEITCM').'</th>
														<th>'.__('Time','SEITCM').'</th>
													</tr>';
									$scorearr = seitcm_get_list_periodicreviews($seitcm_class_id,$seitcm_row->ID);
									foreach ($scorearr as $perio){
										$detail .= '<tr>
														<td>'.$perio->points.'</td>
														<td>'.seitcm_get_skill_name($perio->skill).'</td>
														<td>'.seitcm_create_date_from_mysql($perio->time).'</td>
													</tr>';
										$total += $perio->points;
									}
									$detail .= '</table></div>';
									$average = count($scorearr)==0 ? '' : round($total/count($scorearr),2);
									echo '<strong class="seitcm_click_detail" id="call_periodicpreviews_detail_'.$seitcm_row->ID.'">'. $average .'</strong>';
									?>
									<div title="Detail periodic peviews score for <?php echo get_user_meta($seitcm_row->ID, 'first_name', true)?>"
		    							id="periodicpreviews_detail_<?php echo $seitcm_row->ID?>">
										<?php echo $detail;?>
									</div>
									<script type="text/javascript">
			    						$(document).ready(function() {
			    							$( "#periodicpreviews_detail_<?php echo $seitcm_row->ID?>" ).dialog({
			    							      autoOpen: false,
			    							      modal: true,
			    							      width: 400,
			    							      show: {
			    							          effect: "blind",
			    							          duration: 100
			    							        },
			    							        hide: {
			    							          effect: "blind",
			    							          duration: 100
			    							        }
			    							    });
	
			    							$("#call_periodicpreviews_detail_<?php echo $seitcm_row->ID?>").click(function() {
			    							      $( "#periodicpreviews_detail_<?php echo $seitcm_row->ID?>" ).dialog( "open" );
			    							    });
		    							});
		    						</script>
								</td>
								<td>
									<?php 
									$detail = '<div style="height:200px; overflow-y:scroll; border: 1px #cfcfcf solid;border-radius: 5px 5px 0px 0px;margin-top: 5px;"><table class="seitcm_grid">
													<tr>
														<th>'.__('Result','SEITCM').'</th>
														<th colspan="4">'.__('Detail','SEITCM').'</th>
													</tr>';
									$scorearr = seitcm_get_list_examinationscores($seitcm_class_id,$seitcm_row->ID);
									echo '<strong class="seitcm_click_detail" id="call_examinationscores_detail_'.$seitcm_row->ID.'">';
									$x=0;
									$y=0;
									foreach ($scorearr as $exam){
										
										$total = $exam->skill1 == '-1' ? 0 : $exam->skill1;
										$total += $exam->skill2 == '-1' ? 0 : $exam->skill2;
										$total += $exam->skill3 == '-1' ? 0 : $exam->skill3;
										$total += $exam->skill4 == '-1' ? 0 : $exam->skill4;
										$count = $exam->skill1 == '-1' ? 0 : 1;
										$count += $exam->skill2 == '-1' ? 0 : 1;
										$count += $exam->skill3 == '-1' ? 0 : 1;
										$count += $exam->skill4 == '-1' ? 0 : 1;
										$result = $count ==0 ? ' ' : round($total/$count,2,true).' ';
										$skill1 = $exam->skill1 == '-1' ? '' : $exam->skill1;
										$skill2 = $exam->skill2 == '-1' ? '' : $exam->skill2;
										$skill3 = $exam->skill3 == '-1' ? '' : $exam->skill3;
										$skill4 = $exam->skill4 == '-1' ? '' : $exam->skill4;
										echo ++$x==1? $result : '| '.$result;
										$str_row= '<tr>
														<td rowspan="2" style="text-align:center">
															<span style="font-size:18px; line-height:25px; color:#EE1D24;">'.$result.'</span><br />
															<span style="font-size:12px;">'.seitcm_create_date_from_mysql($exam->time).'</span>
														</td>
														<td>'.seitcm_get_skill_name(1).'</td>
														<td>'.seitcm_get_skill_name(2).'</td>
														<td>'.seitcm_get_skill_name(3).'</td>
														<td>'.seitcm_get_skill_name(4).'</td>
													<tr>
														<td>'.$skill1.'</td>
														<td>'.$skill2.'</td>
														<td>'.$skill3.'</td>
														<td>'.$skill4.'</td>
													</tr><tr style="height:1px;"><td colspan="5" style="height:1px; border-top:2px solid #999;"></td></tr>';
										$detail .= $str_row;
									}
									'</strong>';
									$detail .= '</table></div>';
									?>
									<div title="Detail examination scores for <?php echo get_user_meta($seitcm_row->ID, 'first_name', true)?>"
		    							id="examinationscores_detail_<?php echo $seitcm_row->ID?>">
										<?php echo $detail;?>
									</div>
									<script type="text/javascript">
			    						$(document).ready(function() {
			    							$( "#examinationscores_detail_<?php echo $seitcm_row->ID?>" ).dialog({
			    							      autoOpen: false,
			    							      modal: true,
			    							      width: 550,
			    							      show: {
			    							          effect: "blind",
			    							          duration: 100
			    							        },
			    							        hide: {
			    							          effect: "blind",
			    							          duration: 100
			    							        }
			    							    });
	
			    							$("#call_examinationscores_detail_<?php echo $seitcm_row->ID?>").click(function() {
			    							      $( "#examinationscores_detail_<?php echo $seitcm_row->ID?>" ).dialog( "open" );
			    							    });
		    							});
		    						</script>
								</td>		
								
								<?php if(current_user_can('seitcm_scores_update')) {?>					
								<td>
		    						<div class="modal_dialog" 
		    							title="Add periodic peviews score for <?php echo get_user_meta($seitcm_row->ID, 'first_name', true)?>"
		    							id="periodicpreviews_input_<?php echo $seitcm_row->ID?>">
		    						<form method="post" class="seitcm_form" action="admin.php?page=seitcm_class_option_menu&module=score&class=<?php echo $seitcm_class_id?>&action=periodicpreviews&student=<?php echo $seitcm_row->ID?>"><fieldset>
		    							<label><?php _e('Skill','SEITCM')?></label>
		    							<select class="seitcm_skill" name="seitcm_skill">
		    								<option value=""><?php _e('Chose skill','SEITCM')?></option>
		    								<?php 
		    								global $seitcm_score_skill;
		    								foreach ($seitcm_score_skill as $skill)
		    								{
		    								?>
		    									<option value="<?php echo $skill['key']?>"><?php echo $skill['Value']?></option>
		    								<?php
		    								}
		    								?>
		    							</select>
		    							<label><?php _e('Score','SEITCM')?></label>
		    							<input type="text" name="seitcm_score">
		    							<label></label>
		    							<span class="seitcm_button_wrapper">
		    								<input type="submit" value="<?php _e('Save','SEITCM')?>" id="submit_periodicpreviews_input_<?php echo $seitcm_row->ID?>">
		    								<input type="button" value="<?php _e('Cancel','SEITCM')?>" id="close_periodicpreviews_input_<?php echo $seitcm_row->ID?>">
		    							</span>
		    						</fieldset></form>	    						
		    						</div>
		    						<script type="text/javascript">
			    						$(document).ready(function() {
			    							$( "#periodicpreviews_input_<?php echo $seitcm_row->ID?>" ).dialog({
			    							      autoOpen: false,
			    							      modal: true,
			    							      width: 400,
			    							      show: {
			    							          effect: "blind",
			    							          duration: 100
			    							        },
			    							        hide: {
			    							          effect: "blind",
			    							          duration: 100
			    							        }
			    							    });
	
			    							$("#call_periodicpreviews_input_<?php echo $seitcm_row->ID?>").click(function() {
			    							      $( "#periodicpreviews_input_<?php echo $seitcm_row->ID?>" ).dialog( "open" );
			    							    });
			    							$("#close_periodicpreviews_input_<?php echo $seitcm_row->ID?>").click(function() {
			    							      $( "#periodicpreviews_input_<?php echo $seitcm_row->ID?>" ).dialog( "close" );
			    							    });
			    							$("#submit_periodicpreviews_input_<?php echo $seitcm_row->ID?>").click(function() {
			    							      $( "#periodicpreviews_input_<?php echo $seitcm_row->ID?>" ).dialog( "close" );
			    							    });
			    							$('.seitcm_skill').mouseover(function()
		    								    {
		    								       $('select.seitcm_skill option').css("font-family","Trebuchet MS").css("font-size","9px");        
		    								    });
		    							});
		    						</script>
		    						<a class="seitcm_button" id="call_periodicpreviews_input_<?php echo $seitcm_row->ID?>"><?php _e('Periodic Reviews','SEITCM')?></a>
		    					</td>
							</tr>
							<?php 
							}
						}
						?>
				</tbody></table>
			</div>
		</div>
	</div>